package com.qumitech.visualnovel.service.account;


import com.alibaba.fastjson.JSONArray;
import com.qumitech.visualnovel.model.dao.console.SysPermission;
import com.qumitech.visualnovel.datasource.console.SysRolePermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRolePermissionServiceImpl implements SysRolePermissionService {
    @Autowired
    SysRolePermissionMapper sysRolePermissionMapper;

    @Override
    public void setSysRolePermission(int roleId, JSONArray permissionIdArray) {
        sysRolePermissionMapper.unBindSysRolePermission(roleId);
        List<Integer> permissionIdList = JSONArray.parseArray(permissionIdArray.toJSONString(), Integer.class);
        sysRolePermissionMapper.bindSysRolePermission(roleId, permissionIdList);
    }

    @Override
    public void unBindSysRolePermission(int roleId) {
        sysRolePermissionMapper.unBindSysRolePermission(roleId);

    }

    @Override
    public List<SysPermission> getSysPermissionsByRoleId(int roleId) {
        return sysRolePermissionMapper.getSysPermissionsByRoleId(roleId);
    }
}
